#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.basic.module.operate.controller;

import ${package}.basic.module.operate.service.OperateService;
import ${package}.common.bean.po.Operate;
import ${package}.common.bean.vo.AddOperateVo;
import ${package}.common.bean.vo.DisableOrEnableOperateVo;
import ${package}.common.bean.vo.JsonResult;
import ${package}.common.bean.vo.QueryBean;
import ${package}.common.bean.vo.UpdateOperateVo;
import ${package}.common.emum.ReturnCodeEnum;
import ${package}.common.utils.SnowFlakeUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * Description: 无法补充
 *
 * @author zhang wen yi
 * @date 2019/8/6 15:28
 *
 * <pre>
 *              ${copyright}
 *      Copyright (c) 2019. All Rights Reserved.
 * </pre>
 */
@Slf4j
@RestController
@RequestMapping("/yk_api/operate/")
@AllArgsConstructor
@Api(value = "操作管理")
public class OperateController {

    /**
     * 操作Service
     */
    private OperateService operateService;

    /**
     * Description:
     * <获取操作管理分页列表>
     * @author pig
     * @date 18:02 2019/8/6
     * @param queryBean 1
     * @return JsonResult
     **/
    @PostMapping("queryOperteByLimit")
    @ApiOperation(value = "获取操作管理分页列表",notes = "获取操作管理分页列表")
    @ApiImplicitParam(name = "queryBean",value = "查询条件",dataType = "QueryBean",paramType = "body",required = true)
    public JsonResult<PageInfo<Operate>> queryOperteByLimit(@RequestBody @Valid QueryBean queryBean){
        PageInfo<Operate> pageInfo = operateService.queryOperteByLimit(queryBean);
        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS,pageInfo);
    }

    /**
     * Description:
     * <根据主键查询操作管理信息>
     * @author pig
     * @date 18:02 2019/8/6
     * @param id 1
     * @return JsonResult
     **/
    @GetMapping("queryOperareByKey")
    @ApiOperation(value = "根据主键查询操作管理信息",notes = "根据主键查询操作管理信息")
    @ApiImplicitParam(name = "id",value = "操作主键",dataType = "Long",paramType = "query",required = true)
    public JsonResult<Operate> queryOperareByKey(Long id){
        Operate operate = operateService.queryOperareByKey(id);
        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS,operate);
    }

    /**
     * Description:
     * <新增操作管理信息>
     * @author pig
     * @date 18:03 2019/8/6
     * @param addOperate 1
     * @return JsonResult
     **/
    @PutMapping("addOperate")
    @ApiOperation(value = "新增操作管理信息",notes = "新增操作管理信息")
    @ApiImplicitParam(name = "addOperate",value = "新增操作实体类",dataType = "AddOperateVo",paramType = "body",required = true)
    public JsonResult<Operate> addOperate(@RequestBody @Valid AddOperateVo addOperate){

        Operate operate = new Operate();
        BeanUtils.copyProperties(addOperate, operate);
        operate.setId(SnowFlakeUtil.getID());
        operate.setCreatedate(new Date());
        operateService.addOperate(operate);

        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS, operate);
    }

    /**
     * Description:
     * <根据主键更新操作管理信息>
     * @author pig
     * @date 18:03 2019/8/6
     * @param updateOperateVo 1
     * @return JsonResult
     **/
    @PostMapping("updateOperateByKey")
    @ApiOperation(value = "根据主键更新操作管理信息",notes = "根据主键更新操作管理信息")
    @ApiImplicitParam(name = "updateOperateVo",value = "更新操作实体类",dataType = "UpdateOperateVo",paramType = "body",required = true)
    public JsonResult<Operate> updateOperateByKey(@RequestBody @Valid UpdateOperateVo updateOperateVo){

        Operate operate = new Operate();

        BeanUtils.copyProperties(updateOperateVo,operate);

        operateService.updateOperateByKey(operate);

        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS, operate);
    }

    /**
     * Description:
     * <根据主键删除操作信息>
     * @author pig
     * @date 18:04 2019/8/6
     * @param id 1
     * @return JsonResult
     **/
    @DeleteMapping("deleteOperateByKey/{id}")
    @ApiOperation(value = "根据主键删除操作信息",notes = "根据主键删除操作信息")
    @ApiImplicitParam(name = "id",value = "操作主键",dataType = "Long",paramType = "path",required = true)
    public JsonResult<Long> deleteOperateByKey(@PathVariable("id") Long id){

        operateService.deleteOperateByKey(id);

        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS, id);
    }

    /**
     * Description:
     * <批量删除操作管理>
     * @author pig
     * @date 18:05 2019/8/6
     * @param keys 1
     * @return JsonResult
     **/
    @PostMapping("removeOperatesBykeys")
    @ApiOperation(value = "批量删除操作管理",notes = "批量删除操作管理")
    @ApiImplicitParam(name = "keys",value = "操作主键列表",dataType = "Long",paramType = "body",required = true,allowMultiple = true)
    public JsonResult<List<Operate>> removeOperatesBykeys(@RequestBody List<Long> keys){
        List<Operate> operaters = operateService.removeOperatesBykeys(keys);
        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS,operaters);
    }

    /**
     * Description:
     * <启用/禁用>
     * @author pig
     * @date 18:05 2019/8/6
     * @param disableOrEnableOperateVo 1
     * @return JsonResult
     **/
    @PostMapping("disableOrEnableOperate")
    @ApiOperation(value = "启用/禁用",notes = "启用/禁用")
    @ApiImplicitParam(name = "disableOrEnableOperateVo",value = "启用或禁用操作实体类",dataType = "DisableOrEnableOperateVo",paramType = "body",required = true)
    public JsonResult<Operate> disableOrEnableOperate(@RequestBody @Valid DisableOrEnableOperateVo disableOrEnableOperateVo){

        Operate operate = new Operate();

        BeanUtils.copyProperties(disableOrEnableOperateVo,operate);

        operateService.disableOrEnableOperate(operate);

        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS, operate);
    }

    /**
     * Description:
     * <查询编码是否重复>
     * @author pig
     * @date 18:05 2019/8/6
     * @param code 1
     * @param id 2
     * @return JsonResult
     **/
    @GetMapping("operateVerifyCode")
    @ApiOperation(value = "查询编码是否重复",notes = "查询编码是否重复")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code",value = "编码",dataType = "String",paramType = "query",required = true),
            @ApiImplicitParam(name = "id",value = "主键",dataType = "Long",paramType = "query",required = true)})
    public JsonResult<Boolean> operateVerifyCode(@RequestParam("code") String code, @RequestParam("id") Long id){
        Boolean flag = operateService.operateVerifyCode(code, id);
        return JsonResult.getInstant(ReturnCodeEnum.SUCCESS,flag);
    }
}
